"""
@title(TenX腾晓2024年12月考核答题文件)
@warning(请勿修改参数和返回值)
@warning(请认真填写__init__中的数据)
@author(1323230180)
@license(CC BY-SA 4.0 License)
"""
import os
from copy import deepcopy


class TenXClass:
    def __init__(self):
        # 获取当前文件名并截取文件名的学号-姓名
        file_name = os.path.basename(__file__).split('.')[0].split("-")
        self.id = 3224002027  # 学号
        self.name = "黄子晴"  # 姓名

    @staticmethod
    def question1(*args) -> list[str]:
        binary_tree = deepcopy(args[0])  # 传入的地牢结构（二叉树），详细请看BinaryTree.py

        def find(root):
            def dfs(jiedian, lu, result_l):
                if not jiedian:
                    return
                lu += str(jiedian.value)
                if jiedian.value == 0:
                    result_l.append(lu)
                dfs(jiedian.left, lu, result_l)
                dfs(jiedian.right, lu, result_l)

            result_l = []
            dfs(root, "", result_l)
            return result_l

        return find(binary_tree.root)

    @staticmethod
    def question2(*args) -> str:
        matrix = deepcopy(args[0])  # 传入的河流结构（矩阵）

        def gongfu(h):
            j = []
            for x in h:
                big = max(x)
                j.append(str(big))
            return "".join(j)

        return gongfu(matrix)

    @staticmethod
    def question3(*args) -> int:
        def zhulong():
            mo = 99999999
            n = 1000
            dp = [[0] * 2 for _ in range(n + 1)]  # 不用管循环变量
            dp[1][0] = 5  # 非9长度1的有5个
            dp[1][1] = 1  # 长度1有1个9
            for h in range(2, n + 1):  # 从第二个数字开始
                # 当前是9
                dp[h][1] += dp[h - 1][0] + dp[h - 1][1]  # 累加
                dp[h][1] %= mo
                # 非9，有0，3，4，5，7，8
                dp[h][1] += dp[h - 1][1] * 6
                dp[h][1] %= mo
                dp[h][0] += dp[h - 1][0] * 6
                dp[h][0] %= mo
            return dp[n][1]

        return zhulong()

    @staticmethod
    def question4(*args) -> int:
        n = deepcopy(args[0])  # 用于搭建金字塔的球个数

        def kesi(n):
            total = 0
            x = 1  # 层数
            while True:
                c = x * (x + 1) // 2  # 每一层的珠子数
                total += c
                if total > n:
                    return x -  1
                x += 1

        return kesi(n)

    @staticmethod
    def question5(*args) -> str:
        balls = deepcopy(args[0])  # 五行空间球的初始值

        def wuxing(shuzhi_l):
            balls = shuzhi_l.copy()
            n = len(balls)
            while True:
                for h in range(n):
                    ball1 = balls[(h - 1) % n]
                    ball2 = balls[(h - 2) % n]
                    balls[h] = ball1 + ball2
                    if all(ball >= 10000 for ball in balls):
                        return balls

        return wuxing(balls)